from mediator import mediator
from mediator . tests . test_assistant import make_mediator_test_keyword_args

class application_fake :
    def __init__ ( self ) :
        self . _key_escape_counter = None
        self . _application_window_request = False
        self . _key_escape_counter_request = False
        self . _gui_create_application_window_reply = None
        self . _gui_key_up_event_reply = None
        self . _gui_key_down_event_reply = None
        self . _gui_key_return_event_reply = None
        self . _gui_key_escape_event_reply = None
        self . _gui_key_space_event_reply = None
        self . _gui_key_backspace_event_reply = None
        self . _gui_key_f5_event_reply = None
        self . _gui_key_ctrl_f5_event_reply = None
        self . _gui_global_mouse_button_1_event_reply = None
        self . _gui_any_key_event_reply = None
    def start ( self ) :
        mediator_application_tests . _call_history += [ application_fake . start ]
    def run_main_loop ( self ) :
        self . _main_loop_ran = True
    def quit_application ( self ) :
        self . _application_quited = True
    def application_window_request ( self ) :
        self . _application_window_request = True
    def key_escape_counter_request ( self ) :
        self . _key_escape_counter_request = True
    def gui_create_application_window_reply ( self , window ) :
        self . _gui_create_application_window_reply = window
    def gui_key_up_event_reply ( self , event ) :
        self . _gui_key_up_event_reply = event
    def gui_key_down_event_reply ( self , event ) :
        self . _gui_key_down_event_reply = event
    def gui_key_return_event_reply ( self , event ) :
        self . _gui_key_return_event_reply = event
    def gui_key_escape_event_reply ( self , event ) :
        self . _gui_key_escape_event_reply = event
    def gui_key_space_event_reply ( self , event ) :
        self . _gui_key_space_event_reply = event
    def gui_key_backspace_event_reply ( self , event ) :
        self . _gui_key_backspace_event_reply = event
    def gui_key_f5_event_reply ( self , event ) :
        self . _gui_key_f5_event_reply = event
    def gui_key_ctrl_f5_event_reply ( self , event ) :
        self . _gui_key_ctrl_f5_event_reply = event
    def gui_global_mouse_button_1_event_reply ( self , event ) :
        self . _gui_global_mouse_button_1_event_reply = event
    def gui_any_key_event_reply ( self , event ) :
        self . _gui_any_key_event_reply = event
        
class arbitrary_module_fake :
    def start ( self ) :
        mediator_application_tests . _call_history += [ arbitrary_module_fake . start ]

class mediator_application_tests : 
    'mediator_application'
    def __init__ ( self , test ) :
        mediator_application_tests . _call_history = [ ]
        self . _test = test
        self . _application = application_fake ( )
        self . _mediator = mediator ( )
        self . _mediator . register_modules ( ** make_mediator_test_keyword_args \
            ( 'application' 
            , self . _application 
            , arbitrary_module_fake
            ) )
    def test_start_first ( self ) :
        self . _mediator . start ( )
        self . _test . assume_equal ( mediator_application_tests . _call_history [ 0 ] , application_fake . start )    
    def test_run_main_loop ( self ) :
        self . _mediator . run_main_loop ( )
        self . _test . assume_true ( self . _application . _main_loop_ran )    
    def test_quit_application ( self ) :
        self . _mediator . quit_application ( )
        self . _test . assume_true ( self . _application . _application_quited )    
    def test_application_window_request ( self ) :
        self . _mediator . application_window_request ( )
        self . _test . assume_true ( self . _application . _application_window_request )    
    def test_key_escape_counter_request ( self ) :
        self . _mediator . key_escape_counter_request ( )
        self . _test . assume_true ( self . _application . _key_escape_counter_request )
    def test_gui_create_application_window_reply ( self ) :
        self . _mediator . gui_create_application_window_reply ( 'my window' )
        self . _test . assume_equal ( self . _application . _gui_create_application_window_reply , 'my window' )
    def test_gui_key_up_event_reply ( self ) :
        self . _mediator . gui_key_up_event_reply ( 'my key up' )
        self . _test . assume_equal ( self . _application . _gui_key_up_event_reply , 'my key up' )
    def test_gui_key_down_event_reply ( self ) :
        self . _mediator . gui_key_down_event_reply ( 'my key down' )
        self . _test . assume_equal ( self . _application . _gui_key_down_event_reply , 'my key down' )
    def test_gui_key_return_event_reply ( self ) :
        self . _mediator . gui_key_return_event_reply ( 'my key return' )
        self . _test . assume_equal ( self . _application . _gui_key_return_event_reply , 'my key return' )
    def test_gui_key_escape_event_reply ( self ) :
        self . _mediator . gui_key_escape_event_reply ( 'my key escape' )
        self . _test . assume_equal ( self . _application . _gui_key_escape_event_reply , 'my key escape' )
    def test_gui_key_space_event_reply ( self ) :
        self . _mediator . gui_key_space_event_reply ( 'my key space' )
        self . _test . assume_equal ( self . _application . _gui_key_space_event_reply , 'my key space' )
    def test_gui_key_backspace_event_reply ( self ) :
        self . _mediator . gui_key_backspace_event_reply ( 'my key backspace' )
        self . _test . assume_equal ( self . _application . _gui_key_backspace_event_reply , 'my key backspace' )
    def test_gui_key_f5_event_reply ( self ) :
        self . _mediator . gui_key_f5_event_reply ( 'my key f5' )
        self . _test . assume_equal ( self . _application . _gui_key_f5_event_reply , 'my key f5' )
    def test_gui_key_ctrl_f5_event_reply ( self ) :
        self . _mediator . gui_key_ctrl_f5_event_reply ( 'my key ctrl f5' )
        self . _test . assume_equal ( self . _application . _gui_key_ctrl_f5_event_reply , 'my key ctrl f5' )
    def test_gui_global_mouse_button_1_event_reply ( self ) :
        self . _mediator . gui_global_mouse_button_1_event_reply ( 'my mouse button 1' )
        self . _test . assume_equal ( self . _application . _gui_global_mouse_button_1_event_reply , 'my mouse button 1' )
    def test_gui_any_key_event_reply ( self ) :
        self . _mediator . gui_any_key_event_reply ( 'my any key' )
        self . _test . assume_equal ( self . _application . _gui_any_key_event_reply , 'my any key' )
